/*
 * kleurFont.java
 *
 * Created on 3 mei 2008, 15:28
 */

package client.gui.controls.kleurschema;

import client.gui.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

/**
 *
 * @author  Gonyo
 */
public class KleurFont extends KleurObject  {
    Color col;
    Settings setting;
    /** Creates new form kleurFont */
    public KleurFont(Color c, Settings s) {
        initComponents();
        this.col=c;
        this.setting=s;
        TitledBorder title;
        title = BorderFactory.createTitledBorder("Font kleur velden");
        this.setBorder(title);
        
        txt_Rood.setText(c.getRed()+"");
        txt_Groen.setText(c.getGreen()+"");
        txt_Blauw.setText(c.getBlue()+"");
         addListeners();
        lbl_Rood.setText("R:");
        lbl_Groen.setText("G:");
        lbl_Blauw.setText("B:");
        
        btn_Kleur.setText("Meer kleuren ...");
        btn_Kleur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kleurActionPerformed(evt);
            }
        });
        
        this.setLayout(new FlowLayout());
        this.add(lbl_Rood);   
        this.add(txt_Rood);
        this.add(lbl_Groen);
        this.add(txt_Groen);
        this.add(lbl_Blauw);
        this.add(txt_Blauw);
        this. add(btn_Kleur);
        this.setPreferredSize(new Dimension (400,75));
    }

    public Color getCol() {
        return col;
    }

    public void setCol(Color col) {
        this.col = col;
    }
    
    private void addListeners() {
        txt_Rood.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
        txt_Groen.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
        txt_Blauw.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
    }
    
     private void controleer(java.awt.event.FocusEvent evt) {
        if(Integer.parseInt(((JTextField)evt.getSource()).getText())>=0 &&Integer.parseInt(((JTextField)evt.getSource()).getText())<256) 
           setNieuweKleur(new Color(Integer.parseInt(txt_Rood.getText()),Integer.parseInt(txt_Groen.getText()),Integer.parseInt(txt_Blauw.getText())));

    }
    
     private void kleurActionPerformed(java.awt.event.ActionEvent evt) {
        Kleurkiezer kk =new Kleurkiezer(this); 
        kk.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        kk.pack();
        kk.setLocationRelativeTo(this);
        kk.toon();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public void refresh() {
        txt_Rood.setText(col.getRed()+"");
        txt_Groen.setText(col.getGreen()+"");
        txt_Blauw.setText(col.getBlue()+"");
        
        setting.refreshFont(col);
    }

    @Override
    public void setNieuweKleur(Color c) {
        this.col=c;
        refresh();
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
